package ysm.tools;

import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class Cors {
    @Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration corsConfiguration = new CorsConfiguration();
        /*鏄惁鍏佽璇锋眰甯︽湁楠岃瘉淇℃伅*/
        corsConfiguration.setAllowCredentials(true);
        /*鍏佽璁块棶鐨勫鎴风鍩熷悕*/
        corsConfiguration.addAllowedOrigin("*");
        /*鍏佽鏈嶅姟绔闂殑瀹㈡埛绔姹傚ご*/
        corsConfiguration.addAllowedHeader("*");
        /*鍏佽璁块棶鐨勬柟娉曞悕,GET POST绛�*/
        corsConfiguration.addAllowedMethod("*");
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(urlBasedCorsConfigurationSource);
    }
}